from atomsitecache import AtomsiteCache

class EntityInstance :
	'''this class represents a struct_asym_id i.e. an instance or copy of an entity'''
	def __init__(s, dataconnector, entity_id, struct_asym_id) :
		s.dc = dataconnector
		s.eid, s.said = entity_id, struct_asym_id
	def getStructAsymId(s) : return s.said
	def getChainId(s) :
		'''return the PDB chain id which contains this EntityInstance, assert that it is only one!'''
		if not hasattr(s,'chainid') :
			chains = set()
			for CRIs in AtomsiteCache(s.dc).getESSmapCRI(s.eid,s.said) :
				for chain, resnum, icode in CRIs : chains.add(chain)
			assert len(chains) == 1
			s.chainid = chains.pop()
		return s.chainid
	def getNumModelledGroups(s, modelId) :
		return AtomsiteCache(s.dc).getNumModelledGroups(s.eid,modelId,s.getChainId())
		#return sum(len(x) for x in AtomsiteCache(s.dc).getESSmapCRI(s.eid,s.said))
	def getNumGroupsWithAltconfs(s, modelId) :
		return AtomsiteCache(s.dc).getNumModelledGroupsWithAltconf(s.eid,modelId,s.getChainId())
		return 999
		assert 1==0
	def getNumAtomsWithZeroOccu(s, modelId) :
		return AtomsiteCache(s.dc).getZeroOccuCounts()[(s.eid, modelId, s.getChainId())]
